#include "CController.h"

cController::cController(int slot)
{
	m_controllerSlot = slot - 1;
}

cController::~cController()
{
}

bool cController::isConnected() {
	//Zero out the state of the controller
	ZeroMemory(&m_controllerState, sizeof(XINPUT_STATE));

	DWORD Result = XInputGetState(m_controllerSlot, &m_controllerState);

	if(Result == ERROR_SUCCESS) {
		return true;
	} else {
		return false;
	}
}

XINPUT_STATE cController::getState()
{
	ZeroMemory(&m_controllerState, sizeof(XINPUT_STATE));

	XInputGetState(m_controllerSlot, &m_controllerState);

	return m_controllerState;
}

void cController::vibration(int leftVal, int rightVal)
{
	//Creates a instance of the Vibration interface to
	//control vibration within the game
	XINPUT_VIBRATION	vibration;

	//
	ZeroMemory(&vibration, sizeof(XINPUT_VIBRATION));

	//Runs a check to see if the left value is greater than 0
	//and sets the Vibration of the left motor to the left value
	vibration.wLeftMotorSpeed = leftVal;
	vibration.wRightMotorSpeed = rightVal;

	XInputSetState(m_controllerSlot, &vibration);
}